import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: () => import('@/views/layout/index.vue'),
      children: [
        {
          path: '',
          name: 'home',
          component: () => import('@/views/home/index.vue'),
        },
        {
          path: '/category/:id',
          name: 'category',
          component: () => import('@/views/category/index.vue'),
        },
        {
          path: 'category/sub/:id',
          name: 'subCategory',
          component: () => import('@/views/subCategory/index.vue'),
        },
        {
          path: '/detail/:id',
          name: 'detail',
          component: () => import('@/views/detail/index.vue'),
        },
        {
          path: '/cartlist',
          name: 'cartlist',
          component: () => import('@/views/CartList/index.vue'),
        },
        {
          path: '/checkout',
          name: 'checkout',
          component: () => import('@/views/Checkout/index.vue'),
        },
        {
          path: '/pay',
          name: 'pay',
          component: () => import('@/views/Pay/index.vue'),
        },
        {
          path: '/paycallback',
          name: 'paycallback',
          component: () => import('@/views/Pay/PayCallback.vue'),
        },
        {
          path: '/member',
          redirect: '/member/user',
          name: 'member',
          component: () => import('@/views/Member/index.vue'),
          children: [
            {
              path: 'user',
              name: 'member-user',
              component: () => import('@/views/Member/components/UserInfo.vue'),
            },
            {
              path: 'order',
              name: 'member-order',
              component: () => import('@/views/Member/components/UserOrder.vue'),
            },
          ],
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
    },
  ],
  scrollBehavior() {
    return { top: 0 }
  },
})

export default router
